﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SalesSys.DAL.Base;

namespace SalesSys.DAL.Models
{

    public abstract class StoMapper<T, TID> : BaseMap<T, TID> where T : DbEntityBase<TID>
    {
        public override string TablePrefix
        {
            get { return EntityTabConfig.StockTabPrefix; }
        }
    }
      /// <summary>
    /// 计划单来源类型
    /// </summary>
    public enum DeliveryListSource
    {
        Creater=0,
        Sale
    }
    /// <summary>
    ///出库单
    /// </summary>
    public class DeliveryList: DbEntityBase<Guid>
    {
        public DeliveryList()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 供应商
        /// </summary>
        public virtual Provider Provider { get; set; }

        /// <summary>
        /// 供应商编号
        /// </summary>
        public Guid ProviderId { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public virtual Employee Creater { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 来源
        /// </summary>
        public DeliveryListSource From { get; set; }
        /// <summary>
        /// 销售单id
        /// </summary>
        public Guid? FromId { get; set; }
        /// <summary>
        /// 商品信息
        /// </summary>
        public virtual ICollection<StockGoods> StockGoods { get; set; }

        public class Mapper : StoMapper<DeliveryList, Guid>
        {
            public Mapper()
            {

            }
        }
    }

    /// <summary>
    /// 出入库单商品信息
    /// </summary>
    public class StockGoods: DbEntityBase<Guid>
    {
        /// <summary>
        /// 是否入库
        /// </summary>
        public bool IsIn { get; set; }

        /// <summary>
        /// 商品
        /// </summary>
        public virtual Commodity Commodity { get; set; }
        public virtual DeliveryList DeliveryList { get; set; }
        /// <summary>
        /// 数量
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 每吨运费,入库
        /// </summary>
        public decimal DeliveryPrice { get; set; }

        /// <summary>
        /// 单价,入库
        /// </summary>
        public decimal Price { get; set; }
        /// <summary>
        /// 规范价，统一使用的非标价，入库
        /// </summary>
        public decimal NormPrice { get; set; }
        /// <summary>
        /// 单重，入库
        /// </summary>
        [DecimalPrecision(18, 3)]
        public decimal Weight { get; set; }
        /// <summary>
        /// 总重
        /// </summary>
        [DecimalPrecision(18, 3)]
        public decimal TotalWeight { get; set; }
        /// <summary>
        /// 原价，预估价，入库
        /// </summary>
        public decimal SourcePrice { get; set; }

        public class Mapper : StoMapper<StockGoods, Guid>
        {
            public Mapper()
            {

            }
        }

    }

    /// <summary>
    /// 入库单来源
    /// </summary>
    public enum WarehouseEntrySourcce
    {
        /// <summary>
        /// 手动创建
        /// </summary>
        Creater=0,
        /// <summary>
        /// 采购单创建
        /// </summary>
        Purchase,
        /// <summary>
        /// 退货
        /// </summary>
        ReturnGoods,
        /// <summary>
        /// 冲红单
        /// </summary>
        Offset
    }

    /// <summary>
    /// 入库单类型
    /// </summary>
    public enum WarehouseEntryState
    {
        /// <summary>
        /// 正常
        /// </summary>
        Normal = 0,
        /// <summary>
        /// 已被冲红
        /// </summary>
        Offset
    }

    /// <summary>
    /// 入库单 
    /// </summary>
    public class WarehouseEntry: DbEntityBase<Guid>
    {
        public WarehouseEntry()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 供应商
        /// </summary>
        public virtual Provider Provider { get; set; }

        /// <summary>
        /// 供应商编号
        /// </summary>
        public Guid ProviderId { get; set; }

        /// <summary>
        /// 运费
        /// </summary>
        public decimal DeliveryPrice { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public virtual Employee Creater { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 来源
        /// </summary>
        public WarehouseEntrySourcce From { get; set; }

        /// <summary>
        /// 来源编号
        /// </summary>
        public Guid? FromId { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public WarehouseEntryState  State { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 商品信息
        /// </summary>
        public virtual ICollection<StockGoods> StockGoods { get; set; }

        public class Mapper : StoMapper<WarehouseEntry, Guid>
        {
            public Mapper()
            {

            }
        }
    }
    /// <summary>
    /// 锁库单
    /// </summary>
    public class StockLock: DbEntityBase<Guid>
    {
        /// <summary>
        /// 计划单编号
        /// </summary>
        public  Guid OrderId { get; set; }

        /// <summary>
        /// 锁定总重
        /// </summary>
        [DecimalPrecision(18, 3)]
        public decimal Weight { get; set; }

        /// <summary>
        /// 锁定数量
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 仓库商品
        /// </summary>
        public virtual DepotCommodity DepotCommodity { get; set; }
        /// <summary>
        /// 是否已释放
        /// </summary>
        public bool IsRelease { get; set; }
        public class Mapper : StoMapper<StockLock, Guid>
        {
            public Mapper()
            {

            }
        }
       
         
    }
}
